package com.example.planetexploder.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间相关工具
 * @author 宋熙然
 * 修改日期：2019.10.13
 */
public class TimeUtil {
    /**
     * 获取当前时间
     * 格式："yyMMddHHmmss"
     * @return 当前时间
     */
    public static String getCurrentTime() {
        SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间
        sdf.applyPattern("yyMMddHHmmss");
        Date date = new Date();// 获取当前时间
        return sdf.format(date);
    }

    public static String getDisplayTime(String rawTime){
        String currentTime = TimeUtil.getCurrentTime();
        String mntsec = (rawTime.charAt(6) == '0' ? rawTime.charAt(7) : rawTime.substring(6, 8)) + ":" + rawTime.substring(8, 10);
        String month= (rawTime.charAt(2) != '0') ? rawTime.substring(2, 4) : rawTime.charAt(3)+"";
        String day= (rawTime.charAt(4) != '0') ? rawTime.substring(4, 6) : rawTime.charAt(5)+"";
        if(rawTime.substring(0,6).equals(currentTime.substring(0,6)))
            return mntsec;
        if(rawTime.substring(0,3).equals(currentTime.substring(0,3)))
            return month + "月" + day + "日   " + mntsec;
        return "20" + rawTime.substring(0, 2) + "年" + month + "月" + day + "日 " + mntsec;
    }

}
